package com.hnust.root.dao.mapper.wx;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnust.root.dao.entity.domain.forward.Topic;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface TopicMapper extends BaseMapper<Topic> {

    //增加点赞数
    @Update("update topic set like_count = like_count + 1 where id = #{id}")
    int addUserLikeCount(@Param("id") int topicId);

    //减少点赞数
    @Update("update topic set like_count = like_count - 1 where id = #{id}")
    int decreaseUserLikeCount(@Param("id")int topicId);

    //增加评论数量
    @Update("update topic set comment_count = comment_count + 1 where id = #{id}")
    int addCommentCount(@Param("id")int topicId);

    @Delete("delete from topic where status = 1")
    void scheduledDeleteTopic();
}
